#include "Keyboard.h"
#include <string.h>

//Define the max size of the keyboard buffer as a constant
const static unsigned kuiInputBufferSize = 128;


//Initializate the keyboard input
void cKeyboard::Init()
{
  //Initializate the mabKeyboardInput 
  memset(mabInputBuffer, 0, kuiInputChannelSize);

  //Sucessfull initialization
  mbIsValid = true;
}


//Deinitializate the keyboard input and restore the original controller
void cKeyboard::Deinit()
{
  //Establish the state of the class to uninitialized
  mbIsValid = false;
}


//Update 
void cKeyboard::Update(struct tInputState mState)
{
  if (mState.miKey != -1)
    KeyEventProc(mState.miKey, mState.mbPressed);
}


//Getter to obtain the state of a key
float cKeyboard::Check(unsigned int luiEntry)
{
  if (mabInputBuffer[luiEntry])
    return 1.0f;
  return 0.0f;
}


//Return the state of the initialization 
bool cKeyboard::IsValid()
{
  return mbIsValid;
}


//Private method. Change the state of the key pressed
void cKeyboard::KeyEventProc(unsigned int luiKey, bool lbPressed)
{
  if (luiKey >= 0 && luiKey < kuiInputChannelSize)
    mabInputBuffer[luiKey] = lbPressed;
}
